<template>
	<view class="install">
		<view @click="handleNfc" class="Nfc-1" v-if="!isDot">读取芯片信息</view>
		<view class="po-bot" v-if="isDot">
			<view class="dot"></view>
			<view class="ima">
				<image style="width: 60rpx;height: 60rpx;" src="/static/work/04.png" mode=""></image>
			</view>
		</view>
		<!-- 查看转运箱信息 -->
		<u-popup :show="boxInformation && boxs.id" @close="boxInformation = false" mode="center" round="20rpx">
			<view class="box-Block">
				<view class="box-1">转运箱信息</view>
				<view class="box-flex">
					<view>芯片ID</view>
					<view>{{boxs.id||'-'}}</view>
				</view>
				<view class="box-flex">
					<view>转运箱价值</view>
					<view>{{boxs.boxMoney||'-'}}</view>
				</view>
				<view class="box-flex">
					<view>转运箱子长度</view>
					<view>{{boxs.boxHeight||'-'}}</view>
				</view>
				<view class="box-flex">
					<view>转运箱子宽度</view>
					<view>{{boxs.boxWidth||'-'}}</view>
				</view>
				<view class="box-flex">
					<view>转运箱子高度</view>
					<view>{{boxs.boxDepth||'-'}}</view>
				</view>
				<view class="box-flex">
					<view>转运箱状态</view>
					<view>{{boxs.boxStatus==0?'库内':'库外'}}</view>
				</view>
				<view class="box-but" @click="boxInformation = false">确定</view>
			</view>
		</u-popup>
	</view>
	
	
</template>

<script>
	import {
		getLogisticBox
	} from '@/api/store.js'
	import NFC from './NFC.js'
	export default {
		data() {
			return {
				boxInformation: false, //控制转运箱信息显示和隐藏
				isDot: false, //控制读取芯片样式
				boxs: {}, //转运箱信息
			}
		},
		onLoad() {
			NFC.listenNFCStatus()
			this.handleCustomEventBindRead = this.handleCustomEventRead.bind(this);
			uni.$on('nfcCodds', this.handleCustomEventBindRead);
			setTimeout(() => {
				this.getNfc()
			}, 800)
		},
		methods: {
			// 接口获取转运箱信息
			async getBox(id) {
				let res = await getLogisticBox(id)
				this.boxs = res.data
				this.boxInformation = true
			},
			// 读取到的nfc芯片信息
			handleCustomEventRead(event) {
				console.log('执行:',event);
				if (event.data) {
					this.isDot = false
					this.getBox(event.data)
				} else {
					this.isDot = false
					uni.showToast({
						title: '未读取到芯片信息',
						icon: 'none'
					})
				}
			},
			getNfc() {
				this.isDot = true
				NFC.readData();
			},
			handleNfc(){
				this.isDot = true
				NFC.readData();
			}
		},
		onUnload() {
			uni.$off('nfcCodds')
		},
		
	}
</script>

<style scoped>
	.Nfc-1{
		width: 400rpx;
		height: 80rpx;
		display: flex;
		align-items: center;
		justify-content: center;
		background-color: #177A77;
		color: #FFFFFF;
		font-size: 25rpx;
		border-radius: 15rpx;
		margin-top: 100rpx;
	}
	.install{
		width: 100%;
		height: 100vh;
		display: flex;
		flex-direction: column;
		align-items: center;
	}
	.box-but {
		width: 100%;
		height: 80rpx;
		display: flex;
		align-items: center;
		justify-content: center;
		background-color: #177A77;
		border-radius: 15rpx;
		font-size: 25rpx;
		color: #FFFFFF;
		margin-top: 30rpx;
		margin-bottom: 30rpx;
	}

	.box-flex {
		width: 100%;
		height: 80rpx;
		display: flex;
		align-items: center;
		justify-content: space-between;
		border-bottom: 1rpx solid #cccccc;
		font-size: 25rpx;
	}

	.box-1 {
		width: 100%;
		height: 100rpx;
		font-size: 35rpx;
		font-weight: bold;
		display: flex;
		align-items: center;
		justify-content: center;
	}

	.box-Block {
		width: 650rpx;
		min-height: 400rpx;
		padding: 10rpx 50rpx;
		box-sizing: border-box;
		display: flex;
		flex-direction: column;
		align-items: center;
	}

	.ima {
		width: 100rpx;
		height: 100rpx;
		display: flex;
		align-items: center;
		justify-content: center;
		z-index: 2;
		position: absolute;
		top: 32%;
		z-index: 5;
	}

	.po-bot {
		width: 100%;
		height: 700rpx;
		display: flex;
		align-items: center;
		justify-content: center;
		position: absolute;
		top: 0;
		z-index: 5;
		margin-top: 100rpx;
	}

	.dot {
		width: 70px;
		height: 70px;
		display: block;
		position: absolute;
		border-radius: 50%;
		background-color: #FFFFFF;
		margin-top: -150rpx;
		margin-right: 0rpx;
		z-index: 5;
	}

	.dot::after {
		width: 100%;
		height: 100%;
		content: "";
		border-radius: 50%;
		position: absolute;
		top: 0;
		left: 0;
		z-index: -2;
		background-color: #177A77;
		animation: dot-play 4s linear 400ms infinite;
	}

	.dot::before {
		width: 100%;
		height: 100%;
		content: "";
		border-radius: 50%;
		position: absolute;
		top: 0;
		left: 0;
		z-index: -1;
		background-color: #DDECEB;
		animation: dot-play 4s linear 200ms infinite;
		animation-delay: 2s;
		/* 延迟 2s */
	}

	@keyframes dot-play {
		from {
			transform: scale(1);
			opacity: .2;
		}

		to {
			transform: scale(4);
			opacity: 0;
		}
	}
</style>